#include "attendencewin.h"

#include <QApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>

#include "registerwin.h"
#include "qfaceobject.h"
#include "select.h"

#include <iostream>
#include <QDebug>
#include <iostream>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    std::cout << "hello world" << std::endl;

    // 初始化数据库
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    QString dbPath = QCoreApplication::applicationDirPath() + "/sever.db";
    db.setDatabaseName(dbPath);
    qDebug() << "数据库路径:" << dbPath;
    if (!db.open())
    {
        std::cout << "数据库打开失败: " << db.lastError().text().toStdString() << std::endl;
        return -1;
    }
    QString createsql = "create table if not exists employee(employeeID integer primary key autoincrement,Name varchar(256),sex varchar(256),birthday text, address text,phone text,faceId integer unique,headfile text)";
    QSqlQuery query(db);
    if (!query.exec(createsql))
    {
        std::cout << "创建employee表失败: " << query.lastError().text().toStdString() << std::endl;
    }
    createsql = "create table if not exists attendance(attendaceID integer primary key autoincrement,employeeID integer,attendace TimeStamp NOT NULL DEFAULT(datetime('new','localtime')))";
    if (!query.exec(createsql))
    {
        std::cout << "创建attendance表失败: " << query.lastError().text().toStdString() << std::endl;
    }

    // 只创建主窗口，TabWidget中的自定义控件会自动创建
    attendenceWin w;
    w.show();

    return a.exec();
}
